define(function () {
	
	
	$.paginationDefaultSize = 10;
	
	$.val_trim = function(v){ //判断v的值，如果为undefined,null，则为""
		if(typeof(v) == "undefined" || v == null){
			return "";
		}else{
			return v.trim();
		}
	};
	$.isEmail = function(str){
		var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
		return reg.test(str);
	};
    $.isTel = function(str){
      var reg = /^[0-9]*\d{11}$/;
      return reg.test(str);  
    };
    $.isNullStr = function(val){
        return (val == null || typeof(val) == "undefined" || val.length == 0);
    }
    $.isNull = function(val){
        return (val == null || typeof(val) == "undefined");
    };
    
    $.shortForStr = function(val, count){
    	if($.isNullStr(val)){
    		return "";
    	}else{
    		if(val.length > count){
    			return val.substr(0,count) + "...";
    		}else{
    			return val;
    		}
    	}
    }

    $.redirectTo = function(url){
        if($.isNull(url))
            return;
        location.href=url;
    };

    $.refreshPage = function(){
        location.reload();
    }
    $.setUrlParam = function (name, val, isRedirect) {
    	var p1 = name+"=";
    	if(location.search.indexOf(p1) == -1){
    		var newurl = location.search + "&"+p1+val;
    	}else{
    		var newurl = location.search.substr(0, location.search.indexOf(p1)+p1.length) + val;
    	}
    	
    	if(typeof(isRedirect)=="undefined" || isRedirect){
    		location.search = newurl;
    	}else{
    		return newurl;
    	}
    		
    }
    
    $.getHashUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");  
		var temp_i = window.location.hash.indexOf("?");
        if(temp_i == -1){
        	return null;
        }else{
	        var r = window.location.hash.substr(temp_i + 1).match(reg);  
	        if (r != null) return unescape(r[2]);  
	        return null;  
        }

    };
    
	$.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");  
        var r = window.location.search.substr(1).match(reg);  
        if (r != null) return unescape(r[2]);  
        return null;  
    };

    $.refreshPageToTab = function(index){
    	var tab = $.getUrlParam("tab");
    	if($.isNullStr(tab)){
    		location.search = location.search+"&tab="+index
    	}else{
    		location.reload();
    	}
    }
    
    $.unicodeToHanzi=function(str){
    	if($.isNull(str)){
    		str = "";
    	}
    	return eval("'" + str + "'");
    };
    
    $.toUnicode=function(str){
    	return escape(str).toLocaleLowerCase().replace(/%u/gi,'\\u');
    };
    
    $.ToGB2312=function(str){
    	return unescape(str.replace(/\\u/gi,'%u'));
    };
    
    $.urlSearch=function(w,p,s){
    	if($.isNull(s)){
    		s = $.paginationDefaultSize;
    	}
    	location.search="?w="+$.toUnicode(w)+"&p="+p+"&s="+s;
    }

    $.timeFormat1 = function(timestamp){

        function add0(m){return m<10?'0'+m:m }
        var time = new Date(timestamp);
        var y = time.getFullYear();
        var m = time.getMonth()+1;
        var d = time.getDate();
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
        return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm);//+':'+add0(s);
    }
    $.timeFormat2 = function(timestamp){

        function add0(m){return m<10?'0'+m:m }
        var time = new Date(timestamp);
        var y = time.getFullYear();
        var m = time.getMonth()+1;
        var d = time.getDate();
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
//		"2016-10-22T13:00"
        return y+'-'+add0(m)+'-'+add0(d)+'T'+add0(h)+':'+add0(mm);//+':'+add0(s);

    }
    
	$.removeVirguleOfBegin = function(a) {
		while (a.substr(0, 1) == "/") {
			a = a.substr(1, a.length);
		}
		return a;
	};
	$.removeVirguleOfEnd = function(a) {
		while (a.substr(a.length - 1) == "/") {
			a = a.substr(0, a.length - 1);
		}
		return a;
	};
	$.handleUrl = function(url) {

		if (typeof(url) == 'undefined' || url == null) {
			return null;
		}
		var indexhttp = url.indexOf("http://");
		if (indexhttp != -1) { // http://xxx.sss.xxx.jpg 网络地址，直接访问
			return url;
		}
		//服务器地址的相对路径 /asset/i/ssss.jpg
		return this.removeVirguleOfBegin(url);

	};
});
